/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.reduce.klsh.kmeaning.reducers;

import aiaudio.database.tables.ReduceDictionaryTable;
import java.io.IOException;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableReducer;

/**
 *
 * @author nastya
 */
public class KMeansDictionaryReducer extends TableReducer<ImmutableBytesWritable, ImmutableBytesWritable, ImmutableBytesWritable> {

    @Override
    protected void reduce(ImmutableBytesWritable key, Iterable<ImmutableBytesWritable> values, Context context) throws IOException, InterruptedException {
        Put put = new Put(key.get());
        int coordinateNum = 0;
        for (ImmutableBytesWritable artist : values) {
            ReduceDictionaryTable.addCentroid(put, coordinateNum, artist.get());
            coordinateNum++;
        }
        context.write(new ImmutableBytesWritable(key), put);
    }
}
